package com.erp.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.erp.dto.CountResult;
import com.erp.pojo.Customer;
import com.erp.service.CustomerService;
import com.erp.mapper.CustomerMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * @author Teacher
 * @description 针对表【t_customer】的数据库操作Service实现
 * @createDate 2025-05-13 09:10:04
 */
@Service
public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer>
    implements CustomerService{

    //注入Mapper
    @Autowired
    private CustomerMapper customerMapper;
    @Override
    public Map<String, Object> queryCustListService(Integer pageNum, Integer pageSize) {
        Map<String, Object> result=new HashMap<>();
        //创建封装分页查询参数的Page对象
        Page page=new Page(pageNum,pageSize);
        System.out.println(page.getTotal());
        List list = customerMapper.selectList(page, null);
        System.out.println(page.getTotal());

        result.put("custList",list);
        result.put("total",page.getTotal());
        return result;
    }

    @Override
    public List<Customer> queryCustIdNameListService() {
        QueryWrapper<Customer> wrapper=new QueryWrapper<>();
        //指定列的投影，指定select id,cust_name
        wrapper.select("id","cust_name");
        List<Customer> customerList = customerMapper.selectList(wrapper);
        return customerList;
    }
    @Override
    public List<CountResult> countCustService() {
        return customerMapper.countCustomerAreaMapper();
    }

    @Override
    @Async
    public void asyncSave(Customer customer) {
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        save( customer);
    }
}




